package j05zuoye;

import j05zuoye.bean.RaceInfo;

import java.util.*;

public class J1 {
    public static void main(String[] args) {
        Map<Integer, RaceInfo> racemap = new TreeMap<>();
        racemap.put(1930, new RaceInfo("第一届", 1930, "乌拉圭", "乌拉圭"));
        racemap.put(1934, new RaceInfo("第二届", 1934, "意大利", "意大利"));
        racemap.put(1938, new RaceInfo("第三届", 1938, "法国", "意大利"));
        racemap.put(1950, new RaceInfo("第四届", 1950, "巴西", "乌拉圭"));
        racemap.put(1954, new RaceInfo("第五届", 1954, "瑞士", "西德"));
        racemap.put(1958, new RaceInfo("第六届", 1958, "瑞典", "巴西"));
        racemap.put(1962, new RaceInfo("第七届", 1962, "智利", "巴西"));
        racemap.put(1966, new RaceInfo("第八届", 1966, "英格兰", "英格兰"));
        racemap.put(1970, new RaceInfo("第九届", 1970, "墨西哥", "巴西"));
        racemap.put(1974, new RaceInfo("第十届", 1974, "前西德", "西德"));
        racemap.put(1978, new RaceInfo("第十一届", 1978, "阿根廷", "阿根廷"));
        racemap.put(1982, new RaceInfo("第十二届", 1982, "西班牙", "意大利"));
        racemap.put(1986, new RaceInfo("第十三届", 1986, "墨西哥", "阿根廷"));
        racemap.put(1990, new RaceInfo("第十四届", 1990, "意大利", "西德"));
        racemap.put(1994, new RaceInfo("第十五届", 1994, "美国", "巴西"));
        racemap.put(1998, new RaceInfo("第十六届", 1998, "法国", "法国"));
        racemap.put(2002, new RaceInfo("第十七届", 2002, "韩日", "巴西"));
        racemap.put(2006, new RaceInfo("第十八届", 2006, "德国", "意大利"));
        racemap.put(2010, new RaceInfo("第十九届", 2010, "南非", "西班牙"));
        racemap.put(2014, new RaceInfo("第二十届", 2014, "巴西", "德国"));
        racemap.put(2018, new RaceInfo("第二十一届", 2018, "俄罗斯", "法国"));

//        int year = 200;
        int year = 2018;
        RaceInfo raceInfo = racemap.get(year);
        if(raceInfo==null){
            System.out.println("没有举办世界杯");
        }else {
            System.out.println(raceInfo);
        }

        String winner = "巴西";
        /*
        Set<Map.Entry<Integer,RaceInfo>> entrySet = racemap.entrySet();
        // 假如没有得过冠军
        boolean have = false;
        //正常遍历
        for (Map.Entry<Integer,RaceInfo> entry: entrySet) {
            RaceInfo temp = entry.getValue();
            if(winner.equals(temp.getWinner())){
                //找到了冠军年份
                have = true;
                System.out.print(entry.getKey()+" ");
            }
        }
        if(!have){
            System.out.println("没有得过冠军");
        }*/

        //stream流 *
        Collection<RaceInfo> infoList = racemap.values();
//        boolean have = false;
        infoList.stream()
                .filter(el->el.getWinner().equals(winner))
                .forEach(el-> {
//                    have = true;
                    System.out.print(el.getYear()+" ");
                });
    }
}
